package com.yuanian.ecsplus.codeautomation.code;

public class CodeBuilder {

    private StringBuilder code = new StringBuilder();

    public CodeBuilder() {
    }

    /**
     * 追加字符串
     * @param str
     * @return
     */
    public CodeBuilder append(String str) {
        code.append(str).append(" ");
        return this;
    }

    /**
     * 结束一行
     * @return
     */
    public CodeBuilder endLine() {
        //删除空格
        code.deleteCharAt(code.length());
        code.append(";").append("\\r\\n");
        return this;
    }

    public CodeBuilder startNest() {
        //删除空格
        code.deleteCharAt(code.length());
        code.append("{").append("\\r\\n");
        return this;
    }

    /**
     * 开始一行
     * @param nestNum
     * @return
     */
    public CodeBuilder startLine(int nestNum) {
        for (int i = 0; i < nestNum; i++) {
            code.append("\\t");
        }
        return this;
    }

    public String toString() {
        return code.toString();
    }
}
